package my.set;

import my.tree.RBTree;

import java.util.Comparator;

/**
 * <p>
 * 用红黑树实现集合
 * </p>
 *
 * @author AJun
 * @since 2020/8/31
 */
@SuppressWarnings("unused")
public class TreeSet<E> implements Set<E> {

    private final RBTree<E> rbTree;

    public TreeSet() {
        this(null);
    }

    public TreeSet(Comparator<E> comparator) {
        rbTree = new RBTree<>(comparator);
    }

    @Override
    public int size() {
        return rbTree.size();
    }

    @Override
    public boolean isEmpty() {
        return rbTree.isEmpty();
    }

    @Override
    public void clear() {
        rbTree.clear();
    }

    @Override
    public boolean contains(E element) {
        return rbTree.contains(element);
    }

    @Override
    public void add(E element) {
        rbTree.add(element);
    }

    @Override
    public void remove(E element) {
        rbTree.remove(element);
    }

    @Override
    public void traversal(Visitor<E> visitor) {
        rbTree.inorder(visitor::visit);
    }

}
